package com.sghd.candy.module.bag.manager;

import com.sghd.candy.module.system.service.CacheLife;
import com.sghd.common.ramcache.anno.Inject;
import com.sghd.common.ramcache.service.EntityCacheService;
import com.sghd.pojo.candy.bag.enums.PropType;
import org.springframework.stereotype.Component;

/**
 * @author Allen
 * @date 2018/12/26
 */
@Component
public class PlayerBagManager implements CacheLife {
    @Inject
    private EntityCacheService<Long, PlayerBag> playerBagCache;

    public PlayerBag getPlayerBag(long playerId) {
        return playerBagCache.loadOrCreate(playerId, builder -> PlayerBag.valueOf(playerId));
    }

    public void change(PlayerBag playerBag, PropType propType, long changeNum) {
        playerBag.change(propType, changeNum);
    }

    @Override
    public void writeBack(Object id) {
        playerBagCache.writeBack(id);
    }
}
